package com.daxia.ogmall.service;

import java.math.BigDecimal;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.daxia.ogmall.dao.OrderStatisticsDAO;
import com.daxia.ogmall.dto.OrderStatisticsDTO;

@Service
public class OrderStatisticsService {
	@Autowired
	private OrderStatisticsDAO orderStatisticsDAO;
	
	public List<OrderStatisticsDTO> findForMonth(OrderStatisticsDTO dto) {
		return orderStatisticsDAO.findForMonth(dto);
	}
	
	public List<OrderStatisticsDTO> findForDay(OrderStatisticsDTO dto) {
		return orderStatisticsDAO.findForDay(dto);
	}
	
	public List<OrderStatisticsDTO> findForYear(OrderStatisticsDTO dto) {
		return orderStatisticsDAO.findForYear(dto);
	}
	
	public List<OrderStatisticsDTO> findForQuarter(OrderStatisticsDTO dto) {
		return orderStatisticsDAO.findForQuarter(dto);
	}
	
	public OrderStatisticsDTO findAllSubAccount(OrderStatisticsDTO dto) {
		List<OrderStatisticsDTO> companys = orderStatisticsDAO.findAllCompany(dto);
		Integer companyCount = 0;
		if (companys != null && companys.size() > 0) {
			companyCount = companys.get(0).getQuantity();
		}
		OrderStatisticsDTO m = new OrderStatisticsDTO();
		m.setQuantity(companyCount);
		m.setAmount(new BigDecimal((companyCount)*5000));
		return m;
	}
	
	public List<OrderStatisticsDTO> findSubAccountForMonth(OrderStatisticsDTO dto) {
		List<OrderStatisticsDTO> designers = orderStatisticsDAO.findCompanyCountForMonth(dto);
		for (OrderStatisticsDTO d : designers) {
			d.setAmount(new BigDecimal((d.getQuantity())*5000));
		}
		return designers;
	}
}
